<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters">
                <el-form-item label="运营商" prop="operatoruid">
                    <el-select v-model="filters.operatoruid" filterable clearable placeholder="请选择运营商">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in operator"
                                :key="item.operatoruid"
                                :label="item.operatorname"
                                :value="item.operatoruid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="供货商" prop="useruuid"  >
                    <el-select v-model="filters.useruuid" clearable placeholder="请选择供货商" filterable  >
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option v-if="usersUp && usersUp.length > 0"
                                v-for="item in usersUp"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.useruuid">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="省份" prop="provinceuuid">
                    <el-select v-model="filters.provinceuuid" filterable clearable placeholder="请选择省份" >
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in info"
                                :key="item.provincename"
                                :label="item.provincename"
                                :value="item.provincename">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="业务类型" prop="busuuid">
                    <el-select v-model="filters.busuuid" filterable clearable placeholder="请选择业务类型">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in bus"
                                :key="item.busuuid"
                                :label="item.busname"
                                :value="item.busuuid">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="filters.productCode" clearable placeholder="产品编码"></el-input>
                </el-form-item>
                <el-form-item label="分销商" prop="downShopName"   >
                    <el-select v-model="filters.downShopName" clearable filterable  placeholder="请选择分销商" >
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in users"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.username">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="filters.upOrderId" clearable placeholder="平台上游单号"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="filters.phoneNum" clearable placeholder="手机号码"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="filters.upfacevalue" clearable placeholder="面值"></el-input>
                </el-form-item>
                <el-form-item label="订单状态"   >
                    <el-select v-model="filters.statu" filterable clearable placeholder="请选择订单状态">
                        <el-option value="0" label="全部">全部</el-option>
                        <el-option
                                v-for="item in status"
                                :key="item.id"
                                :label="item.name"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="回调状态"   >
                    <el-select v-model="filters.callback" clearable filterable placeholder="请选择回调状态">
                        <el-option value="-1" label="全部">全部</el-option>
                        <el-option value="0" label="等待回调">等待回调</el-option>
                        <el-option value="1" label="回调成功">回调成功</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-date-picker type="datetime" placeholder="开始时间" format="yyyy-MM-dd HH:mm:ss"   v-model="filters.createtime" style="width: 100%;"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-date-picker type="datetime" clearable placeholder="结束时间" format="yyyy-MM-dd HH:mm:ss"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-input type="textarea" v-model="filters.upOrderIds"  clearable placeholder="平台上游单号批量"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="findUpOrder">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="successOrderList">批量成功</el-button>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" v-on:click="failtOrderList">批量失败</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="exportdataUpOrder">导出</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="failtOrderDialog = true">订单导入</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="repeatOrderListVisible"  >批量重提</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="repeatOrderStatus" >订单重置</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="orders" highlight-current-row v-loading="listLoading" max-height="620" border @selection-change="selsChange" style="width: 100%;">
            <el-table-column type="selection" width="55">
            </el-table-column>
<!--            <el-table-column prop="downRechargeFlow.downorderuuid" width="280px"  label="订单号">-->
<!--            </el-table-column>-->
            <el-table-column prop="userOrder.username" label="供货商" show-overflow-tooltip  width="100px"  >
            </el-table-column>
            <el-table-column prop="downShopName" label="分销商" show-overflow-tooltip  width="100px"   >
            </el-table-column>
            <el-table-column prop="operatorname" label="运营商"  width="100px" show-overflow-tooltip  >
            </el-table-column>
            <el-table-column prop="province" label="省份" show-overflow-tooltip  >
            </el-table-column>
            <el-table-column prop="cityName" label="地市" show-overflow-tooltip >
            </el-table-column>
            <el-table-column prop="upShopPro.businessType.busname"  width="100px"  show-overflow-tooltip  label="业务类型">
            </el-table-column>
            <el-table-column prop="upShopPro.productCode"  width="100px"  show-overflow-tooltip  label="产品编码">
            </el-table-column>
            <el-table-column prop="upphonenum" width="130px" show-overflow-tooltip  label="充值号码" >
            </el-table-column>
            <el-table-column prop="rechargeamount"  width="100px" label="实际金额"  show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="discountAmount" label="扣款金额" show-overflow-tooltip  width="120px">
            </el-table-column>
            <el-table-column prop="upShopPro.productName" label="产品名称" show-overflow-tooltip  width="140px">
            </el-table-column>
            <!--<el-table-column prop="uprechargenum" label="充值数量" >-->
            <!--</el-table-column>-->
<!--            <el-table-column prop="upShopPro.productName" label="产品名称" width="150px">-->
<!--            </el-table-column>-->
            <el-table-column prop="discount" width="100px" show-overflow-tooltip  label="折扣">
            </el-table-column>
            <el-table-column prop="upShopPro.upfacevalue" label="面值" width="90px" :formatter="productType">
            </el-table-column>
            <el-table-column prop="status" label="状态" width="100px"  :formatter="formatStatus">
                <template slot-scope="scope">
                    <el-tag :type="scope.row.status == 2 ? 'success' : scope.row.status == 3 ?  'danger' : 'info'"   >{{scope.row.status === 1 ? '充值中' : scope.row.status === 2 ? '充值成功' : scope.row.status === 3 ? "充值失败" : scope.row.status === 4 ? "成功后取消的订单" :
                        scope.row.status === 5 ? "等待充值" :  scope.row.status === 6 ? "退款成功" :  scope.row.status === 7 ? "退款失败" :  scope.row.status === 8 ? "失败后取消的订单"
                        : scope.row.status === 9 ? "缓存订单" : scope.row.status === 10 ? "压单" :  scope.row.status === 11 ? "人工" : '未知' }} </el-tag>
                </template>
            </el-table-column>
            <!--<el-table-column prop="fastchargetype" label="快慢类型" :formatter="formatType">-->
            <!--</el-table-column>-->
            <el-table-column prop="callBack" label="回调状态"  width="100px"  :formatter="callStatus">
            </el-table-column>
            <el-table-column prop="createtime" width="172px" label="充值时间">
            </el-table-column>
            <el-table-column prop="upendtime" width="172px" label="完成时间">
            </el-table-column>
            <!--<el-table-column prop="upendtimesec" label="完成时间毫秒数" >-->
            <!--</el-table-column>-->
            <!--<el-table-column prop="upreqnum" label="已轮训请求次数" >-->
            <!--</el-table-column>-->
            <el-table-column prop="downRechargeFlow.downorderuuid" width="280px" show-overflow-tooltip   label="下游单号" >
            </el-table-column>
            <el-table-column prop="upOrderId" width="190px" show-overflow-tooltip  label="渠道单号" >
            </el-table-column>
            <el-table-column prop="remark" label="备注" width="290px" show-overflow-tooltip>
            </el-table-column>

            <el-table-column label="操作" width="305" fixed="right">
                <template scope="scope">
                    <el-button size="small" @click="voucherOrder(scope.$index, scope.row,'1')">凭证
                    </el-button>
                    <el-button size="small" @click="voucherOrder(scope.$index, scope.row,'2')">催单
                    </el-button>
<!--                    <el-button size="small" @click="voucherOrder(scope.$index, scope.row,'3')">维护-->
<!--                    </el-button>-->
                    <el-button size="small" @click="failtOrder(scope.$index, scope.row)">充值失败
                    </el-button>

                    <el-button size="small" @click="successOrder(scope.$index, scope.row)">充值成功
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-pagination
                @current-change="handleCurrentChange"
                @size-change="handleSizeChange"
                layout="total,sizes,prev, pager, next"
                :total="total">
        </el-pagination>

        <el-dialog title="导入失败订单" v-model="failtOrderDialog" :close-on-click-modal="false">
            <el-form>
                <el-upload
                        class="avatar-uploader"
                        :limit="1"
                        action=""
                        ref="upload"
                        :on-change="handleChange"
                        :file-list="fileList"
                        :auto-upload="false"
                >
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">只能上传固定的xls/xlsx文件。</div>
                </el-upload>
                <el-form-item align="right">
                    <el-button size="small" type="primary" @click="onCancel" style="margin-top: 20px;">取消</el-button>
                    <el-button size="small" type="primary" @click="onSubmit" style="margin-top: 20px;">确认</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="批量提单" width="100%" v-model="batchFormVisible" :close-on-click-modal="false">
            <el-form :model="batchForm" label-width="100px" :inline="true" ref="batchForm">
                <el-form-item label="供货商" prop="useruuid" >
                    <el-select v-model="batchForm.useruuid" filterable placeholder="请选择供货商"   >
                        <el-option v-if="usersUp && usersUp.length > 0"
                                v-for="item in usersUp"
                                :key="item.user.useruuid"
                                :label="item.user.username"
                                :value="item.user.useruuid">
                        </el-option>
                    </el-select>
                    <br/>
                    <span style="color: red;">1.选择需要提交的渠道</span>
                    <br/>
                    <span style="color: red;">2.如果选择当前渠道则是直接提交</span>
                    <br/>
                    <span style="color: red;">3.选择其他渠道是转单提交</span>
                    <br/>
                    <span>当前提交条数:{{currentNum}} 条</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="batchFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="batchFormCommit" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
    import util from '../../common/js/util'
    //import NProgress from 'nprogress'
    import {
        findUpOrder,
        findAllUpShopInfo,
        findAllPro,
        findAllBus,
        exportdataUpOrder,
        getOperatorListPage, findAllDownShopInfo,repeatOrderStatus
    } from '../../api/api';
    import {failtOrder,successOrder,failtOrderList,successOrderList,batchCommitOrder} from '../../api/api';
    import ElOption from "../../../node_modules/element-ui/packages/select/src/option.vue";
    import moment from 'moment';

    export default {
        components: {ElOption},
        data() {
            return {
                currentNum:0,
                filters: {
                    name: '',
                    createtime: moment().subtract('hour', 1).format('YYYY-MM-DD HH:mm:ss'),
                    endtime:'',
                    useruuid:'',
                    uporderuuid:'',
                    upOrderId:'',
                    operatoruid:'',
                    //上游订单号
                    upOrderIds:'',
                    productCode:'',
                    provinceuuid:'',
                    busuuid:'',
                    phoneNum:'',
                    statu:'',
                    callback:'',
                    upfacevalue:'',
                    downShopName:''
                },
                failtOrderDialog : false,
                total: 0,
                start: 0,
                status:[{id:"1",name:"充值中",value:"1"},{id:"2",name:"充值成功",value:"2"} ,
                    {id:"3",name:"充值失败",value:"3"},
                    {id:"5",name:"等待充值",value:"5"},
                    {id:"10",name:"压单 ",value:"10"},{id:"11",name:"人工 ",value:"11"}],
                pageSize: 10,
                listLoading: false,
                orders: [],
                usersUp:[],
                info:[],
                bus:[],
                dataList: [],
                fileList: [],
                operator: [],
                users:[],
                sels: [],//列表选中列
                batchFormVisible:false,
                addLoading: false,
                batchForm:{
                    useruuid:'',
                    size:0,
                    uporderuuids:[]
                }
            }
        },
        methods: {
            onCancel() {
                this.failtOrderDialog = false;
            },
            callStatus: function (row, column) {
//                  0等待回调中 1 回调成功 2 失败 3 下游也在使用此值  4 订单发送到上游失败  5发送订单到上游成功
                return row.callBack === 1 ? '回调成功' : row.callBack ===  0 ? '等待回调' : row.callBack ===  2 ? "订单失败": '未知';
            },
            productType: function (row, column) {
                return (row.upShopPro.businessType.busname == "手机") ? (row.upShopPro.upfacevalue + '话费') : ( row.upShopPro.businessType.busname == "固话") ?  (row.upShopPro.upfacevalue + '话费') :(row.upShopPro.upfacevalue + 'M');
            },
            formatStatus: function (row, column) {
                column.color = "#67C23A";
                return row.status === 1 ? '充值中' : row.status === 2 ? '充值成功' : row.status === 3 ? "充值失败" : row.status === 4 ? "成功后取消的订单" :
                                row.status === 5 ? "等待充值" :  row.status === 6 ? "退款成功" :  row.status === 7 ? "退款失败" :  row.status === 8 ? "失败后取消的订单" :
                                    row.status === 10 ? "压单" :  row.status === 11 ? "人工" : '未知';
            },
            formatType: function (row, column) {
//                 快慢类型  1 快 0慢
                return row.fastchargetype == "1" ? '快充' : row.fastchargetype == "0" ? '慢充': '未知';
            },
            findAllUpShopInfo:function(){
                let para = {
                  test:''
                };
                findAllUpShopInfo(para).then(datas =>{
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.usersUp = data;
                    }
                });
            },findAllPro(){
                let para = {
                    test:''
                };
                findAllPro(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.info = data;
                    }
                });
            },findAllBus(){
                let para = {
                    test:''
                };
                findAllBus(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.bus = data;
                    }
                });
            },
            findUpOrder (){
                let para = {
                    start: this.start,
                    pageSize: this.pageSize,
                    useruuid: this.filters.useruuid == "0" ? "" : this.filters.useruuid,
                    createtime: (this.filters.createtime == "" || this.filters.createtime == undefined) ? "" : moment(this.filters.createtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    endtime:  (this.filters.endtime == "" || this.filters.endtime == undefined)  ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    uporderuuid: this.filters.uporderuuid,
                    upOrderId: this.filters.upOrderId,
                    upOrderIds: this.filters.upOrderIds,
                    productCode:this.filters.productCode,
                    operatoruid:this.filters.operatoruid == "0" ? "" : this.filters.operatoruid,
                    provinceuuid:this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
                    busuuid:this.filters.busuuid == "0" ? "" : this.filters.busuuid,
                    phoneNum:this.filters.phoneNum,
                    status : this.filters.statu == "0" ? "" : this.filters.statu,
                    callback:this.filters.callback == "-1" ? "" : this.filters.callback,
                    upfacevalue:this.filters.upfacevalue,
                    downShopName:this.filters.downShopName
                };
                findUpOrder(para).then((datas) => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else if(data && data.result){
                        this.orders = data.result;
                        this.total = data.totalCount;
                    }
                    this.listLoading = false;
                });
            }, exportdataUpOrder:function () {
                let para = {
                    useruuid: this.filters.useruuid == "0" ? "" : this.filters.useruuid,
                    createtime: (!this.filters.createtime || !this.filters.createtime)? "" : moment(this.filters.createtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    endtime: this.filters.endtime == "" ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    uporderuuid: this.filters.uporderuuid,
                    upOrderId: this.filters.upOrderId,
                    upOrderIds: this.filters.upOrderIds,
                    productCode:this.filters.productCode,
                    operatoruid:this.filters.operatoruid == "0" ? "" : this.filters.operatoruid,
                    provinceuuid:this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
                    busuuid:this.filters.busuuid == "0" ? "" : this.filters.busuuid,
                    phoneNum:this.filters.phoneNum,
                    status : this.filters.statu == "0" ? "" : this.filters.statu,
                    callback:this.filters.callback == "-1" ? "" : this.filters.callback,
                    upfacevalue:this.filters.upfacevalue,
                    downShopName:this.filters.downShopName
                };
                    exportdataUpOrder(para).then(res => {
                    let {message, code, data} = res;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        if(data.path){
                            this.$message({
                                message: "订单导出成功,请稍后进入导出列表下载",
                                type: 'info'
                            });
                        }
                    }
                });
            },
            cancelOrder:function(index, row){
                this.$confirm('确认取消该订单吗?', '提示', {
                    type: 'warning'
                }).then(() => {

                }).catch(() => {

                });
            }
            ,handleCurrentChange: function (val) {
                this.start = val - 1;
                this.findUpOrder();
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                this.findUpOrder();
            }
            ,
            failtOrderList:function(){
                if(this.sels != null  && this.sels.length > 0){
                    let str = "";
                    for(var i = 0 ; i < this.sels.length;i++){
                        str+= this.sels[i].upphonenum;
                        this.sels[i].downorderuuid = this.sels[i].downRechargeFlow.downorderuuid
                    }
                    this.$confirm('确认批量失败订单吗？订单电话号码:'+str, '提示', {}).then(() => {
                        let para = {
                            downorderuuids: this.sels
                        };
                        failtOrderList(para).then((datas) => {
                            this.listLoading = false;
                            let {message, code, data} = datas;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            }
                            this.$message({
                                message: message,
                                type: 'info'
                            });
                            this.findUpOrder();
                        });
                    });
                }else{
                    this.$message({
                        message: "请选择订单",
                        type: 'error'
                    });
                }
            },
            failtOrder:function (index, row) {
                this.$confirm('确认手工失败订单吗？订单电话号码:'+row.upphonenum, '提示', {}).then(() => {
                    let para = {
                        downorderuuid: row.downRechargeFlow.downorderuuid
                    };
                    failtOrder(para).then((datas) => {
                        this.listLoading = false;
                        let {message, code, data} = datas;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        }
                        this.$message({
                            message: message,
                            type: 'info'
                        });
                        this.findUpOrder();
                    });
                });
            }
            ,
            successOrder:function (index, row) {
                this.$confirm('确认手工成功订单吗？订单电话号码:'+row.upphonenum, '提示', {}).then(() => {
                    let para = {
                        downorderuuid: row.downRechargeFlow.downorderuuid
                    };
                    successOrder(para).then((datas) => {
                        this.listLoading = false;
                        let {message, code, data} = datas;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        }
                        this.$message({
                            message: message,
                            type: 'info'
                        });
                        this.findUpOrder();
                    });
                });
            },successOrderList:function () {
                let str = "";
                for(var i = 0 ; i < this.sels.length;i++){
                    str+= this.sels[i].upphonenum;
                    this.sels[i].downorderuuid = this.sels[i].downRechargeFlow.downorderuuid
                }
                this.$confirm('确认手工批量成功订单吗？订单电话号码:'+str, '提示', {}).then(() => {
                    let para = {
                        downorderuuids: this.sels
                    };
                    successOrderList(para).then((datas) => {
                        this.listLoading = false;
                        let {message, code, data} = datas;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        }
                        this.$message({
                            message: message,
                            type: 'info'
                        });
                        this.findUpOrder();
                    });
                });
            },selsChange: function (sels) {
                this.sels = sels;
                this.currentNum = sels.length;
            },handleChange(file, fileList) {
                this.fileTemp = file.raw
                if (this.fileTemp) {
                    if ((this.fileTemp.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
                        || (this.fileTemp.type === 'application/vnd.ms-excel')) {
                        this.importfxx(this.fileTemp)
                    } else {
                        this.$message({
                            type: 'warning',
                            message: '附件格式错误，请删除后重新上传！'
                        })
                    }
                } else {
                    this.$message({
                        type: 'warning',
                        message: '请上传附件！'
                    })
                }
            },importfxx(obj) {
                let _this = this
                let inputDOM = this.$refs.inputer
                // 通过DOM取文件数据
                this.file = event.currentTarget.files[0]
                var rABS = false // 是否将文件读取为二进制字符串
                var f = this.file
                var reader = new FileReader()
                // if (!FileReader.prototype.readAsBinaryString) {
                FileReader.prototype.readAsBinaryString = function(f) {
                    var binary = ''
                    var rABS = false // 是否将文件读取为二进制字符串
                    var pt = this
                    var wb // 读取完成的数据
                    var outdata;
                    var reader = new FileReader()

                    reader.onload = function(e) {
                        var bytes = new Uint8Array(reader.result)
                        var length = bytes.byteLength
                        for (var i = 0; i < length; i++) {
                            binary += String.fromCharCode(bytes[i])
                        }
                        var XLSX = require('xlsx')
                        if(rABS) {
                            wb = XLSX.read(btoa(fixdata(binary)), { // 手动转化
                                type: 'base64'
                            })
                        } else {
                            wb = XLSX.read(binary, {
                                type: 'binary'
                            })
                        }
                        // outdata就是你想要的东西
                        outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
                        this.da = [...outdata]
                        if (_this.default) {
                            _this.dataList = outdata
                        } else {
                            _this.importForm(outdata)
                        }
                    }
                    reader.readAsArrayBuffer(f)
                }
                if (rABS) {
                    reader.readAsArrayBuffer(f)
                } else {
                    reader.readAsBinaryString(f)
                }
            },importForm(outdata) {
                this.dataList = []
                outdata.forEach((value, index, arr) => {

                    const orderId = value['订单号'];
                    if(orderId){
                        this.filters.upOrderIds += orderId +",";
                        this.dataList.push(orderId)
                    }
                })
                this.filters.upOrderIds = this.filters.upOrderIds.substring(0,this.filters.upOrderIds.lastIndexOf(","));
            },onSubmit() {
                this.failtOrderDialog = false;
                console.table(this.filters.upOrderIds)
            },
            repeatOrderListVisible(){
                if(this.sels != null  && this.sels.length > 0){
                    let str = "";
                    for(var i = 0 ; i < this.sels.length;i++){
                        if(this.sels[i].status != 10 && this.sels[i].status != 11 ){
                            this.$message({
                                message: "只能处理订单状态为人工或者压单的订单",
                                type: 'error'
                            });
                            return;
                        }
                        str+= this.sels[i].upphonenum;
                        this.sels[i].uporderuuid = this.sels[i].uporderuuid
                        this.batchForm.useruuid = this.sels[i].userOrder.useruuid;
                    }
                    this.batchFormVisible = true;
                }else{
                    this.$message({
                        message: "请选择订单",
                        type: 'error'
                    });
                }
            },
            repeatOrderList(){
                if(this.sels != null  && this.sels.length > 0){
                    let str = "";
                    for(var i = 0 ; i < this.sels.length;i++){
                        if(this.sels[i].status != 10 && this.sels[i].status != 11 ){
                            this.$message({
                                message: "只能处理订单状态为人工或者压单的订单",
                                type: 'error'
                            });
                            return;
                        }
                        str+= this.sels[i].upphonenum;
                        this.sels[i].uporderuuid = this.sels[i].uporderuuid
                    }
                    this.$confirm('确认批量重新提交订单吗？订单电话号码:'+str, '提示', {}).then(() => {
                        this.batchForm.uporderuuids = this.sels;
                        this.batchFormVisible = false;
                        batchCommitOrder(this.batchForm).then((datas) => {
                            this.listLoading = false;
                            let {message, code, data} = datas;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            }else {
                                this.$message({
                                    message: message,
                                    type: 'info'
                                });
                            }
                            this.findUpOrder();
                        });
                    });
                }else{
                    this.$message({
                        message: "请选择订单",
                        type: 'error'
                    });
                }
            },
            //订单状态重置
            repeatOrderStatus(){
                if(this.sels != null  && this.sels.length > 0){
                    let str = "";
                    for(var i = 0 ; i < this.sels.length;i++){
                        if(this.sels[i].status != 1 ){
                            this.$message({
                                message: "只能处理订单状态为充值中的订单",
                                type: 'error'
                            });
                            return;
                        }
                        str+= this.sels[i].upphonenum;
                        this.sels[i].uporderuuid = this.sels[i].uporderuuid
                    }
                    this.$confirm('确认批量重置订单状态吗？订单电话号码:'+str, '提示', {}).then(() => {
                        this.batchForm.uporderuuids = this.sels;
                        repeatOrderStatus(this.batchForm).then((datas) => {
                            let {message, code, data} = datas;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            }else {
                                this.$message({
                                    message: message,
                                    type: 'info'
                                });
                            }
                            this.findUpOrder();
                        });
                    });
                }else{
                    this.$message({
                        message: "请选择订单",
                        type: 'error'
                    });
                }
            },
            batchFormCommit(){
                this.repeatOrderList();
            }
            ,getOperatorListPage() {
                let para = {
                    start: 1,
                    pageSize:101,
                    operatorname:'',
                };
                this.listLoading = true;
                getOperatorListPage(para).then((datas) => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else if(data && data.result){
                        this.operator = data.result;
                    }
                });
            },findAllDownShopInfo:function(){
                let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
                findAllDownShopInfo(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        if(data){
                            this.users = data;
                        }
                    }
                });
            },
            voucherOrder(index,row,type){
                let voucher = "";
                //凭证
                if(type == "1"){
                    voucher = "充值号码: "+row.upphonenum+" 面值: "+row.upShopPro.upfacevalue+" 充值时间: "+row.createtime+" 充值凭证";
                }else if(type == "2"){
                    //吹单
                    voucher = "充值号码: "+row.upphonenum+" 面值:"+row.upShopPro.upfacevalue+" 充值时间: "+row.createtime+" 卡单,请及时处理!";
                }else if(type == "3"){
                    voucher = row.operatorname +" "+ row.province+" 产品维护,恢复后通知!";
                }

                let copyInput = document.createElement('input');//创建input元素
                document.body.appendChild(copyInput);//向页面底部追加输入框
                copyInput.setAttribute('value', voucher);//添加属性，将url赋值给input元素的value属性
                copyInput.select();//选择input元素
                document.execCommand("Copy");//执行复制命令
                //复制之后再删除元素，否则无法成功赋值
                copyInput.remove();//删除动态创建的节点
                this.$message({
                    message: "复制凭证成功:"+voucher,
                    type: 'info'
                });
            }
        },
        async mounted() {
            await this.findAllDownShopInfo();
        },
        async created(){
            await this.findAllUpShopInfo();
            await this.getOperatorListPage();
            await this.findAllPro();
            await this.findAllBus();
            await this.findUpOrder();
        }
    }

</script>

<style scoped>

</style>
